package com.prs.crm.action.approval;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.domain.approval.AppDataDemand;
import com.prs.crm.domain.approval.ShenQingType;
import com.prs.crm.service.approval.AppDataDemandService;
import com.prs.crm.service.approval.ShenQingTypeService;

public class AppDataDemandAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private AppDataDemand appDataDemand;
	private AppDataDemandService appDataDemandService;
	private List<ShenQingType> shenQingType;
	private ShenQingTypeService shenQingTypeService;
	private String typeIds;
	public List<ShenQingType> getShenQingType() {
		return shenQingType;
	}
	public void setShenQingType(List<ShenQingType> shenQingType) {
		this.shenQingType = shenQingType;
	}
	public String getTypeIds() {
		return typeIds;
	}
	public void setTypeIds(String typeIds) {
		this.typeIds = typeIds;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public AppDataDemand getAppDataDemand() {
		return appDataDemand;
	}
	public void setAppDataDemand(AppDataDemand appDataDemand) {
		this.appDataDemand = appDataDemand;
	}
	public AppDataDemandService getAppDataDemandService() {
		return appDataDemandService;
	}
	public void setAppDataDemandService(AppDataDemandService appDataDemandService) {
		this.appDataDemandService = appDataDemandService;
	}
	public ShenQingTypeService getShenQingTypeService() {
		return shenQingTypeService;
	}
	public void setShenQingTypeService(ShenQingTypeService shenQingTypeService) {
		this.shenQingTypeService = shenQingTypeService;
	}
	@Action("selectAppDataDemandTree")
	public String selectAppDataDemandTree(){
		return SUCCESS;
	}
	@Action("listAppDataDemand")
	public String listAppDataDemand(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(AppDataDemand.class);
//		criteria.add(Restrictions.in("shenQingType", this.getAppDataDemandService().convertByType(typeIds)));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getAppDataDemandService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editAppDataDemand")
	public String editAppDataDemand(){
		shenQingType=this.getShenQingTypeService().getAllShenQingTypes();
		return SUCCESS;
	}
	@Action(value = "saveAppDataDemand", results = {
			@Result(name = "success", type = "redirect", location = "selectAppDataDemandTree"),
			@Result(name = "error", type = "chain", location = "editAppDataDemand") })
	public String saveAppDataDemand(){
		appDataDemand.setType("表单查询视图");
		this.getAppDataDemandService().save(appDataDemand);
		return SUCCESS;
	}
	@Action("selectAppDataDemandTrees")
	public String selectAppDataDemandTrees(){
		return SUCCESS;
	}
	
	@Action(value = "removeAppDataDemand", results = {
			@Result(name = "success", type = "redirect", location = "selectAppDataDemandTree"),
			@Result(name = "error", type = "chain", location = "editAppDataDemand") })
	public String removeAppDataDemand(){
		this.getAppDataDemandService().remove(appDataDemand);
		return SUCCESS;
	}
}
